package impl;

import anaydis.sort.SorterType;
import org.jetbrains.annotations.NotNull;

import java.util.Comparator;
import java.util.List;

public class HSort extends AbstractSorter {
    private int h;

    public HSort() {
        super(SorterType.H);
        h = 1;
    }

    public HSort(SorterType shell) {
        super(shell);
    }

    @Override
    public <T> void sort(@NotNull Comparator<T> comparator, @NotNull List<T> list) {
        hSort(comparator, list, h);
    }

    protected <T> void hSort(Comparator<T> comparator, List<T> list, int h) {
        for (int i = h; i < list.size(); i++) {

            for (int j = i ; j >= h && !greater(comparator,list, j, j - h ); j -= h) {
                swap(list, j, j - h);
            }
        }
    }

}